#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

namespace ywx {
	class string {
	public:
		string(const char* str = "0")
			:_size(strlen(str))
			,_capacity(_size)
			,_str(new char[_capacity + 1])
		{
			strcpy(_str, str);
		}
		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = 0;
			_capacity = 0;
		}

		void swap(string& s)
		{
			std::swap(_str, s._str);
			std::swap(_size, s._size);
			std::swap(_capacity, s._capacity);
		}

		string(const string& s)
			:_str(nullptr)
			,_size(0)
			,_capacity(0)
		{
			string tmp(s._str);
			swap(tmp);
		}

		const char* c_str() const
		{
			return _str;
		}

		char& operator[](size_t pos);
		const char& operator[](size_t pos) const;

		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return _str;
		}
		const_iterator begin() const
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}
		const_iterator end() const
		{
			return _str + _size;
		}

		void reserve(size_t n = 0);

		void push_back(const char c);

		string& operator+=(const char c);
		string& operator+=(const char* str);

		string& append(const string& str);
	private:
		size_t _size;
		size_t _capacity;
		char* _str;
	public:
		static size_t npos;
	};
};

